﻿function drawBiaoTi() {
    for (var i = 0; i < mData.length; i++) {

        var fontSize = 0;
        var x = mCenter + mRadius * Math.cos(mAngle * i);
        var y = mCenter + mRadius * Math.sin(mAngle * i);
        linPoints.push({ x: x, y: y });

        x = x - 45;
        y = y - 10;

        var s_width = ctx3.measureText(mData[i][0]).width; //获取当前绘画的字体宽度、82
        if (parseInt(x) == mCenter) {
            if (y > mCenter) {
                y = y + fontSize;
            } else {
                y = y - fontSize;
            }
        } else if (x > mCenter) {
            x = x + 40;
        } else {
            x = x - 40;
        }
        k = i;
        var rec = new cce.Rectangle(x, y, 90, 20, '#fff', i);
        container.addChild(rec);
        rec.draw();
        rec.addListener("mouseover", function (e, i) {
            var i = e.target.i;
            showTit(i);
        });
        rec.addListener("mouseout", function () {
            hiddenTit();
        });
    }
    console.log(linPoints);
}


function drawTitleButton(x, y, width, height, radius, color, type) {
    ctx3.beginPath();
    ctx3.moveTo(x, y + radius);
    ctx3.lineTo(x, y + height - radius);
    ctx3.quadraticCurveTo(x, y + height, x + radius, y + height);
    ctx3.lineTo(x + width - radius, y + height);
    ctx3.quadraticCurveTo(x + width, y + height, x + width, y + height - radius);
    ctx3.lineTo(x + width, y + radius);
    ctx3.quadraticCurveTo(x + width, y, x + width - radius, y);
    ctx3.lineTo(x + radius, y);
    ctx3.quadraticCurveTo(x, y, x, y + radius);
    ctx3[type + 'Style'] = color || params.color;
    ctx3.closePath();
    ctx3[type]();
}
function drawTitleText() {
    canvas.getContext('2d')["fill"]();
    ctx3.fillStyle = '#000';
    var fontSize = 14;
    ctx3.font = fontSize + 'px Microsoft Yahei';
    ctx3.textAlign = "center";  // 文本居中
    ctx3.fillText('项目配比安全区域', 125, 509);
    ctx3.fillText('货值最大化配比曲线', 297, 509);
    ctx3.fillText('现金流回正需求曲线', 465, 509);
}
function createRegionPoints(name) {
    var lineArr = [];
    for (var i = 0; i < mCount; i++) {
        var x = mCenter + mRadius * Math.cos(mAngle * i) * mData[i][name] / 100;
        var y = mCenter + mRadius * Math.sin(mAngle * i) * mData[i][name] / 100;
        lineArr.push({ x: x, y: y });
    }
    RegionsPoints = lineArr;
}
function createRegionPointxjls(k) {
    var lineArr = [];
    for (var i = 0; i < mCount; i++) {
        var x = mCenter + mRadius * Math.cos(mAngle * i) * mData[i].xjl[k] / 100;
        var y = mCenter + mRadius * Math.sin(mAngle * i) * mData[i].xjl[k] / 100;
        lineArr.push({ x: x, y: y });

    }
    RegionsPoints = lineArr;
}
function createRegionPointsjxl2(k) {
    var lineArr = [];
    for (var i = 0; i < mCount; i++) {
        var x = mCenter + mRadius * Math.cos(mAngle * i) * mData[i].xjl[k] / 104;
        var y = mCenter + mRadius * Math.sin(mAngle * i) * mData[i].xjl[k] / 104;
        lineArr.push({ x: x, y: y });

    }
    RegionsPoints = lineArr;
}
function createRegionPoints2(name) {
    var lineArr = [];
    for (var i = 0; i < mCount; i++) {
        var x = mCenter + mRadius * Math.cos(mAngle * i) * mData[i][name] / 104;
        var y = mCenter + mRadius * Math.sin(mAngle * i) * mData[i][name] / 104;
        lineArr.push({ x: x, y: y });
    }
    RegionsPoints = lineArr;
}
function SubOneArr(arr) {
    var arrNew = [];
    for (var i = 0; i < arr.length; i++) {
        arrNew.push({ x: arr[i].x * 1.1, y: arr[i].y * 1.1 });
    }
    return arrNew;
}
//画雷达图一周围字
function setTxtInfo() {
    for (var i = 0; i < mData.length; i++) {
        var setTxt = new cce.SetText(i, mCenter, mCount, mRadius, mColorLines, mAngle, mData);
        container.addChild(setTxt);
        setTxt.draw();
    }
}
//按钮颜色控制
function setBtnColor() {
    drawTitleButton(arrXmpb[0].x, arrXmpb[0].y, arrXmpb[0].width, arrXmpb[0].height, arrXmpb[0].radius, isxmpb ? xmpbColor : '#ccc', 'fill');
    drawTitleButton(arrHzzdh[0].x, arrHzzdh[0].y, arrHzzdh[0].width, arrHzzdh[0].height, arrHzzdh[0].radius, ishzzdh ? hzzdhColor : '#ccc', 'fill');
    drawTitleButton(arrXjl[0].x, arrXjl[0].y, arrXjl[0].width, arrXjl[0].height, arrXjl[0].radius, isxjl ? xjlColor : '#ccc', 'fill');
}
//项目配比事件
function ReXmpbDraw() {
    Polygon.draw();
    setTxtInfo();
    drawBiaoTi();
    Lines.draw();
    setBtnColor();
    drawTitleText();
    if (isxmpb) {
        LinesRegion.draw();
        Region.draw();
        LinesRegion2.draw();
        Region1.draw();
    }
    if (ishzzdh) {
        LinesHuozhi.draw();
        LinesHuozhiRegion1.draw();
        LinesHuozhiRegion2.draw();
    }
    if (isxjl) {
        crateXjl();
        //LinesXainJing.draw();
        //LinesXainJingRegion1.draw();
        //LinesXainJingRegion2.draw();
        //LinesXainJing1.draw();
        //LinesXainJingRegion11.draw();
        //LinesXainJingRegion21.draw();
    }
    radiusRactHzdh.draw();
    radiusRactXmpb.draw();
    radiusRactXjl.draw();
}
//现金流事件
function ReXjlDraw() {
    Polygon.draw();
    setTxtInfo();
    Lines.draw();
    drawBiaoTi();
    setBtnColor();
    drawTitleText();

    if (isxmpb) {
        LinesRegion.draw();
        Region.draw();
        LinesRegion2.draw();
        Region1.draw();
    }
    if (ishzzdh) {
        LinesHuozhi.draw();
        LinesHuozhiRegion1.draw();
        LinesHuozhiRegion2.draw();
    }
    if (isxjl) {
        crateXjl();
        //LinesXainJing.draw();
        //LinesXainJingRegion1.draw();
        //LinesXainJingRegion2.draw();
        //LinesXainJing1.draw();
        //LinesXainJingRegion11.draw();
        //LinesXainJingRegion21.draw();
    }
    radiusRactXjl.draw();
    radiusRactHzdh.draw();
    radiusRactXmpb.draw();
}
//货值最大化事件
function ReHzdhDraw() {
    Polygon.draw();
    setTxtInfo();
    drawBiaoTi();
    Lines.draw();
    setBtnColor();
    drawTitleText();
    if (isxmpb) {
        LinesRegion.draw();
        Region.draw();
        LinesRegion2.draw();
        Region1.draw();
    }
    if (ishzzdh) {
        LinesHuozhi.draw();
        LinesHuozhiRegion1.draw();
        LinesHuozhiRegion2.draw();
    }
    if (isxjl) {
        //LinesXainJing.draw();
        //LinesXainJingRegion1.draw();
        //LinesXainJingRegion2.draw();
        //LinesXainJing1.draw();
        //LinesXainJingRegion11.draw();
        //LinesXainJingRegion21.draw();
        crateXjl();
    }

    radiusRactXjl.draw();
    radiusRactHzdh.draw();
    radiusRactXmpb.draw();
}
function crateXjl() {
    for (var i = 0; i < mData.length; i++) {
        for (var j = 0; j < mData[i].xjl.length; j++) {

            createRegionPointxjls(j);
            var LinesXainJing = new cce.LinesNoCenter(RegionsPoints, xjlColor);
            container.addChild(LinesXainJing);
            LinesXainJing.draw();
            var LinesXainJingRegion1 = new cce.Region(j, RegionsPoints, "rgb(255, 255, 255,0.01)", "");
            container.addChild(LinesXainJingRegion1);
            LinesXainJingRegion1.draw();
            createRegionPointsjxl2(j);
            var LinesXainJingRegion2 = new cce.Region(j, RegionsPoints, "rgba(255, 255, 255,0.01)", "");
            container.addChild(LinesXainJingRegion2);
            LinesXainJingRegion2.draw();

            LinesXainJingRegion1.addListener("mouseover", function (i, v) {

                if (isxjl)
                    showLineXianJingLiu(i.target.i);
            });
            LinesXainJingRegion1.addListener("mouseout", function () {
                hiddenTit();
            });
            LinesXainJingRegion2.addListener("mouseover", function () {
                hiddenTit();
            });
            LinesXainJingRegion2.addListener("mouseout", function (i, v) {
                if (isxjl)
                    showLineXianJingLiu(i.target.i);
            });

        }
    }
}
function showTit(arrindex) {
    $("#content").css({ "width": "210px", "height": "120px" });
    var str = '<p>';
    str += mData[arrindex].name
    str += '</p>';
    str += "<p style=\"text-align:left;\">项目配比安全区域 ：" + mData[arrindex].xm_min + "~" + mData[arrindex].xm_max + "</p>";
    str += "<p style=\"text-align:left;\">货值最大化配比曲线：" + mData[arrindex].hz + "</p>";
    var temp = "";
    for (var j = 0; j < mData[arrindex].xjl.length; j++) {
        temp += mData[arrindex].xjl[j] + ",";
    }
    str += "<p style=\"text-align:left;\">现金流回正配比：" + temp.substring(0, temp.length - 1) + "</p>";
    $("#content").html(str);
    $("#content").css("display", "block");
}
function showSafeRestion() {
    $("#content").css({ "width": "200px", "height": "" + mCount * 27 + "px" });
    var str = '<p style="text-align:center;">';
    str += '项目配比安全区域';
    str += '</p>';
    for (var i = 0; i < mData.length; i++) {
        str += "<p>" + mData[i].name + "：" + mData[i].xm_min + "～" + mData[i].xm_max + " </p>";
    }
    $("#content").html(str);
    $("#content").css("display", "block");
}
function showLineXianJingLiu(k) {
    $("#content").css({ "width": "200px", "height": "" + mCount * 27 + "px" });
    var str = '<p style="text-align:center;">';
    str += "现金流回正配比曲线组-方案" + k + "";
    str += '</p>';
    for (var i = 0; i < mData.length; i++) {
        str += "<p>" + mData[i].name + "：" + mData[i].xjl[k] + " </p>";

    }
    $("#content").html(str);
    $("#content").css("display", "block");
}
function showLineHuozhiLiu() {
    $("#content").css({ "width": "200px", "height": "" + mCount * 27 + "px" });
    var str = '<p style="text-align:center;">';
    str += '货值最大化配比曲线';
    str += '</p>';
    for (var i = 0; i < mData.length; i++) {
        str += "<p>" + mData[i].name + "：" + mData[i].hz + " </p>";
    }
    $("#content").html(str);
    $("#content").css("display", "block");
}

function hiddenTit() {
    $("#content").html("");
    $("#content").css("display", "none");
}